package org.misalen.web.database.repository.mysql;

import java.util.List;

import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.transform.AliasToBeanResultTransformer;
import org.misalen.web.database.dao.mysql.impl.BaseMySqlDaoImpl;
import org.misalen.web.database.model.mysql.pro.ProUserExtractCash;
import org.misalen.web.database.util.PaginationFrom;
import org.springframework.stereotype.Repository;

@Repository
public class ProUserExtractCashRepository extends BaseMySqlDaoImpl<ProUserExtractCash> {
	public PaginationFrom<ProUserExtractCash> findPageByApply(String state, String belongCity,
			PaginationFrom<ProUserExtractCash> pagination) {
		String sql = "SELECT a.*,b.userName userName,b.mobile mobile,b.withdrawal withdrawal FROM ProUserExtractCash a LEFT JOIN ProUser b ON a.userId=b.primaryKey ";
		if(!belongCity.equals("全国")) {
			sql = sql + "AND b.belongCity='" + belongCity + "' ";
		}
		sql = sql + " where a.state='" + state + "' order by a.addTime desc";
		Session session = this.openSession();
		SQLQuery query = session.createSQLQuery(sql);
		query.setResultTransformer(new AliasToBeanResultTransformer(ProUserExtractCash.class));
		setResultIndex(query, pagination.getPage(), pagination.getRows());
		String countsql = "SELECT count(*) FROM ProUserExtractCash " + " where state='" + state + "'";
		pagination.setTotal(Long.valueOf(session.createSQLQuery(countsql).uniqueResult().toString()));
		@SuppressWarnings("unchecked")
		List<ProUserExtractCash> list = query.list();
		pagination.setList(list);
		closeSession(session);
		return pagination;
	}

}